github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/services/cd-service/pkg/event/event_test.go (about) 1 /*This file is part of kuberpult. 2 3 Kuberpult is free software: you can redistribute it and/or modify 4 it under the terms of the Expat(MIT) License as published by 5 the Free Software Foundation. 6 7 Kuberpult is distributed in the hope that it will be useful, 8 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 MIT License for more details. 11 12 You should have received a copy of the MIT License 13 along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>. 14 15 Copyright 2023 freiheit.com*/ 16 17 package event 18 19 import ( 20 "testing" 21 22 "github.com/go-git/go-billy/v5/memfs" 23 "github.com/google/go-cmp/cmp" 24 ) 25 26 func Test_roundtrip(t *testing.T) { 27 for _, test := range []struct { 28 Name string 29 Event Event 30 }{ 31 { 32 Name: "new-release", 33 Event: &NewRelease{ 34 Environments: map[string]struct{}{ 35 "env1": {}, 36 "env2": {}, 37 }, 38 }, 39 }, 40 { 41 Name: "deployment-basic", 42 Event: &Deployment{ 43 Application: "app", 44 Environment: "env", 45 }, 46 }, 47 { 48 Name: "deployment-1", 49 Event: &Deployment{ 50 Application: "app1", 51 Environment: "env1", 52 SourceTrainEnvironmentGroup: ptr("A"), 53 }, 54 }, 55 { 56 Name: "deployment-2", 57 Event: &Deployment{ 58 Application: "app1", 59 Environment: "env1", 60 SourceTrainEnvironmentGroup: ptr("A"), 61 SourceTrainUpstream: ptr("B"), 62 }, 63 }, 64 { 65 Name: "lock-prevented-deployment", 66 Event: &LockPreventedDeployment{ 67 Application: "app", 68 Environment: "env", 69 LockMessage: "msg", 70 LockType: "application", 71 }, 72 }, 73 } { 74 test := test 75 t.Run(test.Name, func(t *testing.T) { 76 t.Parallel() 77 fs := memfs.New() 78 if err := Write(fs, "test", test.Event); err != nil { 79 t.Fatal("writing event:", err) 80 } 81 result, err := Read(fs, "test") 82 if err != nil { 83 t.Fatal(err) 84 } 85 if diff := cmp.Diff(test.Event, result); diff != "" { 86 t.Error("wrong result:\n", diff) 87 } 88 }) 89 } 90 } 91 92 func ptr[T any](x T) *T { 93 return &x 94 }