Skip to content

Commit

Permalink
Fix sshKey typo in error message (#290)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Marcantonio <jmarcant@redhat.com>

Lint fix

Signed-off-by: Jonathan Marcantonio <jmarcant@redhat.com>

Signed-off-by: Jonathan Marcantonio <jmarcant@redhat.com>
  • Loading branch information
lennysgarage authored Nov 24, 2022
1 parent 49c1373 commit df0b6d3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/subscriber/git/git_subscriber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,15 @@ var _ = Describe("test subscribe invalid resource", func() {

subitem.SubscriberItem.ChannelSecret = chnIncorrectSecret
_, err = subitem.cloneGitRepo()
Expect(err.Error()).To(Equal("ssh_key (and optionally passphrase) or user and accressToken need to be specified in the channel secret"))
Expect(err.Error()).To(Equal("sshKey (and optionally passphrase) or user and accressToken need to be specified in the channel secret"))

chnIncorrectSecret2 := &corev1.Secret{}
err = yaml.Unmarshal([]byte(incorrectSecret2), &chnIncorrectSecret2)
Expect(err).NotTo(HaveOccurred())
subitem.SubscriberItem.ChannelSecret = chnIncorrectSecret2

_, err = subitem.cloneGitRepo()
Expect(err.Error()).To(Equal("ssh_key (and optionally passphrase) or user and accressToken need to be specified in the channel secret"))
Expect(err.Error()).To(Equal("sshKey (and optionally passphrase) or user and accressToken need to be specified in the channel secret"))

err = k8sClient.Delete(context.TODO(), chnSecret)
Expect(err).NotTo(HaveOccurred())
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/gitrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type kubeResource struct {
Kind string `yaml:"kind"`
}

//KKubeResource export the kuKubeResource for other package
// KKubeResource export the kuKubeResource for other package
type KubeResource struct {
kubeResource
}
Expand Down Expand Up @@ -701,7 +701,7 @@ func ParseChannelSecret(secret *corev1.Secret) (string, string, []byte, []byte,
if username == "" || accessToken == "" {
klog.Error(err, "sshKey (and optionally passphrase) or user and accressToken need to be specified in the channel secret")
return username, accessToken, sshKey, passphrase, clientKey, clientCert,
errors.New("ssh_key (and optionally passphrase) or user and accressToken need to be specified in the channel secret")
errors.New("sshKey (and optionally passphrase) or user and accressToken need to be specified in the channel secret")
}
}

Expand Down
74 changes: 72 additions & 2 deletions pkg/utils/gitrepo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/manager"

chnv1 "open-cluster-management.io/multicloud-operators-channel/pkg/apis/apps/v1"
appv1 "open-cluster-management.io/multicloud-operators-subscription/pkg/apis/apps/v1"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

var (
Expand Down Expand Up @@ -1271,3 +1270,74 @@ func TestGetChannelConfigMap(t *testing.T) {
t.Errorf("wanted %v, got %v", cm, returnedConfigMap)
}
}

func TestParseChannelSecret(t *testing.T) {
type args struct {
secret *corev1.Secret
}

tests := []struct {
name string
args args
want string
want1 string
want2 []byte
want3 []byte
want4 []byte
want5 []byte
wantErr bool
}{
{
name: "sshKey need to be specified in the channel secret error",
args: args{&corev1.Secret{}},
want: "",
want1: "",
want2: []byte(nil),
want3: []byte(nil),
want4: []byte(nil),
want5: []byte(nil),
wantErr: true,
},
{
name: "clientKey, clientCert",
args: args{&corev1.Secret{Data: map[string][]byte{
ClientKey: []byte("aaaaaaaaaaa"),
}}},
want: "",
want1: "",
want2: []byte(nil),
want3: []byte(nil),
want4: []byte("aaaaaaaaaaa"),
want5: []byte(nil),
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1, got2, got3, got4, got5, err := ParseChannelSecret(tt.args.secret)
if (err != nil) != tt.wantErr {
t.Errorf("ParseChannelSecret() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("ParseChannelSecret() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("ParseChannelSecret() got1 = %v, want %v", got1, tt.want1)
}
if !reflect.DeepEqual(got2, tt.want2) {
t.Errorf("ParseChannelSecret() got2 = %v, want %v", got2, tt.want2)
}
if !reflect.DeepEqual(got3, tt.want3) {
t.Errorf("ParseChannelSecret() got3 = %v, want %v", got3, tt.want3)
}
if !reflect.DeepEqual(got4, tt.want4) {
t.Errorf("ParseChannelSecret() got4 = %v, want %v", got4, tt.want4)
}
if !reflect.DeepEqual(got5, tt.want5) {
t.Errorf("ParseChannelSecret() got5 = %v, want %v", got5, tt.want5)
}
})
}
}

0 comments on commit df0b6d3

Please sign in to comment.