Skip to content

Commit

Permalink
Add source commit id to new version protocol (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesg authored Dec 18, 2023
1 parent 23e8c3b commit 08fa2a6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ message GetVersionRequest {
message GetVersionResponse {
uint64 version = 1;
google.protobuf.Timestamp deployed_at = 2;
string source_commit_id = 3;
}

service VersionService {
Expand Down
5 changes: 5 additions & 0 deletions services/cd-service/pkg/service/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func (o *VersionServiceServer) GetVersion(
return nil, err
}
res.DeployedAt = timestamppb.New(deployedAt)
release, err := state.GetApplicationRelease(in.Application, *version)
if err != nil {
return nil, err
}
res.SourceCommitId = release.SourceCommitId
}
return &res, nil
}
50 changes: 46 additions & 4 deletions services/cd-service/pkg/service/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import (

func TestVersion(t *testing.T) {
type expectedVersion struct {
Environment string
Application string
ExpectedVersion uint64
ExpectedDeployedAt time.Time
Environment string
Application string
ExpectedVersion uint64
ExpectedDeployedAt time.Time
ExpectedSourceCommitId string
}
tcs := []struct {
Name string
Expand Down Expand Up @@ -81,6 +82,44 @@ func TestVersion(t *testing.T) {
},
},
},
{
Name: "with source commits",
Setup: []repository.Transformer{
&repository.CreateEnvironment{
Environment: "development",
Config: config.EnvironmentConfig{
Upstream: &config.EnvironmentConfigUpstream{
Latest: true,
},
},
},
&repository.CreateEnvironment{
Environment: "staging",
Config: config.EnvironmentConfig{
Upstream: &config.EnvironmentConfigUpstream{
Latest: true,
},
},
},
&repository.CreateApplicationVersion{
Application: "test",
Version: 1,
Manifests: map[string]string{
"development": "dev",
},
SourceCommitId: "deadbeef",
},
},
ExpectedVersions: []expectedVersion{
{
Environment: "development",
Application: "test",
ExpectedVersion: 1,
ExpectedDeployedAt: time.Unix(2, 0),
ExpectedSourceCommitId: "deadbeef",
},
},
},
}
for _, tc := range tcs {
tc := tc
Expand Down Expand Up @@ -121,6 +160,9 @@ func TestVersion(t *testing.T) {
t.Errorf("got wrong deployed at for %s/%s: expected %q but got %q", ev.Application, ev.Environment, ev.ExpectedDeployedAt, res.DeployedAt.AsTime())
}
}
if ev.ExpectedSourceCommitId != res.SourceCommitId {
t.Errorf("go wrong source commit id, expected %q, got %q", ev.ExpectedSourceCommitId, res.SourceCommitId)
}
}
})
}
Expand Down

0 comments on commit 08fa2a6

Please sign in to comment.