-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add common slice helper functions
- Loading branch information
Showing
9 changed files
with
458 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,50 @@ | ||
/* | ||
Copyright 2023 The Katanomi 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 v1alpha1 | ||
|
||
import "errors" | ||
|
||
// GitRepositoryTagOption option for repository tag | ||
// Deprecated: use GitTag instead | ||
type GitRepositoryTagOption struct { | ||
GitRepo | ||
// Tag the name of the tag | ||
Tag string `json:"tag"` | ||
} | ||
|
||
// GitRepositoryTagListOption option for list repository tag | ||
type GitRepositoryTagListOption struct { | ||
GitRepo | ||
} | ||
|
||
// GitTag describe a unique tag | ||
type GitTag struct { | ||
GitRepo | ||
// Tag the name of the tag | ||
Tag string `json:"tag"` | ||
} | ||
|
||
// Validate validate the git repo | ||
func (r *GitTag) Validate() error { | ||
if err := r.GitRepo.Validate(); err != nil { | ||
return err | ||
} | ||
if r.Tag == "" { | ||
return errors.New("tag is empty") | ||
} | ||
return nil | ||
} |
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,83 @@ | ||
/* | ||
Copyright 2023 The Katanomi 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 v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestGitTag_Validate(t *testing.T) { | ||
g := NewWithT(t) | ||
testCases := map[string]struct { | ||
gitTag GitTag | ||
wantErr bool | ||
wantErrMsg string | ||
}{ | ||
"project is empty": { | ||
gitTag: GitTag{ | ||
GitRepo: GitRepo{}, | ||
Tag: "", | ||
}, | ||
wantErr: true, | ||
wantErrMsg: "project is empty", | ||
}, | ||
"repository is empty": { | ||
gitTag: GitTag{ | ||
GitRepo: GitRepo{ | ||
Project: "abc", | ||
}, | ||
Tag: "", | ||
}, | ||
wantErr: true, | ||
wantErrMsg: "repository is empty", | ||
}, | ||
"tag is empty": { | ||
gitTag: GitTag{ | ||
GitRepo: GitRepo{ | ||
Project: "abc", | ||
Repository: "abc", | ||
}, | ||
Tag: "", | ||
}, | ||
wantErr: true, | ||
wantErrMsg: "tag is empty", | ||
}, | ||
"valid case": { | ||
gitTag: GitTag{ | ||
GitRepo: GitRepo{ | ||
Project: "abc", | ||
Repository: "abc", | ||
}, | ||
Tag: "v0.0.1", | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
t.Run(testCase.wantErrMsg, func(t *testing.T) { | ||
err := testCase.gitTag.Validate() | ||
if !testCase.wantErr { | ||
g.Expect(err).Should(Succeed()) | ||
} else { | ||
g.Expect(err).Should(HaveOccurred()) | ||
g.Expect(err.Error()).Should(ContainSubstring(testCase.wantErrMsg)) | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.