-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from swisscom/interface
add client interfaces
- Loading branch information
Showing
8 changed files
with
212 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright 2023 The Crossplane Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package alertmanager | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type AlertManagerClient interface { | ||
GetAlertmanagerConfig(ctx context.Context) (string, map[string]string, error) | ||
CreateAlertmanagerConfig(ctx context.Context, cfg string, templates map[string]string) error | ||
DeleteAlermanagerConfig(ctx context.Context) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Copyright 2023 The Crossplane Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package rulegroups | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cortexproject/cortex-tools/pkg/rules/rwrulefmt" | ||
) | ||
|
||
type RuleGroupClient interface { | ||
GetRuleGroup(ctx context.Context, namespace string, groupName string) (*rwrulefmt.RuleGroup, error) | ||
CreateRuleGroup(ctx context.Context, namespace string, rg rwrulefmt.RuleGroup) error | ||
DeleteRuleGroup(ctx context.Context, namespace string, groupName string) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
Copyright 2022 The Crossplane Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package alertmanager | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" | ||
"github.com/crossplane/crossplane-runtime/pkg/resource" | ||
"github.com/crossplane/crossplane-runtime/pkg/test" | ||
"github.com/crossplane/provider-cortex/internal/clients/alertmanager" | ||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
// Unlike many Kubernetes projects Crossplane does not use third party testing | ||
// libraries, per the common Go test review comments. Crossplane encourages the | ||
// use of table driven unit tests. The tests of the crossplane-runtime project | ||
// are representative of the testing style Crossplane encourages. | ||
// | ||
// https://github.com/golang/go/wiki/TestComments | ||
// https://github.com/crossplane/crossplane/blob/master/CONTRIBUTING.md#contributing-code | ||
|
||
func TestObserve(t *testing.T) { | ||
type fields struct { | ||
service alertmanager.AlertManagerClient | ||
} | ||
|
||
type args struct { | ||
ctx context.Context | ||
mg resource.Managed | ||
} | ||
|
||
type want struct { | ||
o managed.ExternalObservation | ||
err error | ||
} | ||
|
||
cases := map[string]struct { | ||
reason string | ||
fields fields | ||
args args | ||
want want | ||
}{ | ||
// TODO: Add test cases. | ||
} | ||
|
||
for name, tc := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
e := external{service: tc.fields.service} | ||
got, err := e.Observe(tc.args.ctx, tc.args.mg) | ||
if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { | ||
t.Errorf("\n%s\ne.Observe(...): -want error, +got error:\n%s\n", tc.reason, diff) | ||
} | ||
if diff := cmp.Diff(tc.want.o, got); diff != "" { | ||
t.Errorf("\n%s\ne.Observe(...): -want, +got:\n%s\n", tc.reason, diff) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.