diff --git a/cmd/timoni/artifact_push_test.go b/cmd/timoni/artifact_push_test.go index 7b872d0a..82b7f347 100644 --- a/cmd/timoni/artifact_push_test.go +++ b/cmd/timoni/artifact_push_test.go @@ -50,6 +50,14 @@ func Test_PushArtifact(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(output).To(ContainSubstring(aURL)) + // List the artifacts + output, err = executeCommand(fmt.Sprintf( + "artifact list oci://%s", + aURL, + )) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(output).To(ContainSubstring(aTag)) + // Pull the artifact from registry image, err := crane.Pull(fmt.Sprintf("%s:%s", aURL, aTag)) g.Expect(err).ToNot(HaveOccurred()) diff --git a/cmd/timoni/dyff_test.go b/cmd/timoni/dyff_test.go new file mode 100644 index 00000000..6aa5ceed --- /dev/null +++ b/cmd/timoni/dyff_test.go @@ -0,0 +1,48 @@ +/* +Copyright 2023 Stefan Prodan + +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 main + +import ( + "bytes" + "os" + "testing" + + . "github.com/onsi/gomega" +) + +func TestDiffYAML(t *testing.T) { + g := NewWithT(t) + + liveFile, err := os.CreateTemp("", "live") + g.Expect(err).ToNot(HaveOccurred()) + defer os.Remove(liveFile.Name()) + + mergedFile, err := os.CreateTemp("", "merged") + g.Expect(err).ToNot(HaveOccurred()) + defer os.Remove(mergedFile.Name()) + + err = os.WriteFile(liveFile.Name(), []byte("apiVersion: v1\nkind: Pod\nmetadata:\n name: test-pod\n"), 0644) + g.Expect(err).ToNot(HaveOccurred()) + + err = os.WriteFile(mergedFile.Name(), []byte("apiVersion: v1\nkind: Pod\nmetadata:\n name: test-pod-merged\n"), 0644) + g.Expect(err).ToNot(HaveOccurred()) + + buf := new(bytes.Buffer) + err = diffYAML(liveFile.Name(), mergedFile.Name(), buf) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(buf.String()).To(ContainSubstring("name: test-pod-merged")) +} diff --git a/cmd/timoni/version.go b/cmd/timoni/version.go index e077e250..3dec7934 100644 --- a/cmd/timoni/version.go +++ b/cmd/timoni/version.go @@ -64,7 +64,10 @@ func runVersionCmd(cmd *cobra.Command, args []string) error { return err } - cmd.OutOrStdout().Write(marshalled) + _, err = cmd.OutOrStdout().Write(marshalled) + if err != nil { + return err + } return nil } diff --git a/cmd/timoni/version_test.go b/cmd/timoni/version_test.go new file mode 100644 index 00000000..d57e38e2 --- /dev/null +++ b/cmd/timoni/version_test.go @@ -0,0 +1,41 @@ +/* +Copyright 2023 Stefan Prodan + +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 main + +import ( + "testing" + + . "github.com/onsi/gomega" + "sigs.k8s.io/yaml" + + apiv1 "github.com/stefanprodan/timoni/api/v1alpha1" +) + +func TestVersion(t *testing.T) { + g := NewWithT(t) + output, err := executeCommand("version -o yaml") + g.Expect(err).ToNot(HaveOccurred()) + + var data map[string]interface{} + err = yaml.Unmarshal([]byte(output), &data) + g.Expect(err).ToNot(HaveOccurred()) + + expectedAPIVersion := apiv1.GroupVersion.String() + g.Expect(data).To(HaveKeyWithValue("api", expectedAPIVersion)) + g.Expect(data).To(HaveKey("client")) + g.Expect(data).To(HaveKey("cue")) +}