@ -27,6 +27,8 @@ import (
"helm.sh/helm/v4/pkg/release/common"
release "helm.sh/helm/v4/pkg/release/v1"
chart "helm.sh/helm/v4/pkg/chart/v2"
)
func TestHistoryCmd ( t * testing . T ) {
@ -76,6 +78,72 @@ func TestHistoryCmd(t *testing.T) {
runTestCmd ( t , tests )
}
func TestHistoryWithRollback ( t * testing . T ) {
date := time . Unix ( 242085845 , 0 ) . UTC ( )
ch := & chart . Chart {
Metadata : & chart . Metadata {
Name : "foo" ,
Version : "0.1.0-beta.1" ,
AppVersion : "1.0" ,
} ,
}
rels := [ ] * release . Release {
{
Name : "angry-bird" ,
Version : 1 ,
Info : & release . Info {
FirstDeployed : date ,
LastDeployed : date ,
Status : common . StatusSuperseded ,
Description : "Install complete" ,
} ,
Chart : ch ,
} ,
{
Name : "angry-bird" ,
Version : 2 ,
Info : & release . Info {
FirstDeployed : date ,
LastDeployed : date ,
Status : common . StatusSuperseded ,
Description : "Upgrade complete" ,
} ,
Chart : ch ,
} ,
{
Name : "angry-bird" ,
Version : 3 ,
Info : & release . Info {
FirstDeployed : date ,
LastDeployed : date ,
Status : common . StatusDeployed ,
RollbackRevision : 1 ,
Description : "Rollback to 1" ,
} ,
Chart : ch ,
} ,
}
tests := [ ] cmdTestCase { {
name : "history with rollback revision" ,
cmd : "history angry-bird" ,
rels : rels ,
golden : "output/history-with-rollback.txt" ,
} , {
name : "history with rollback revision json" ,
cmd : "history angry-bird --output json" ,
rels : rels ,
golden : "output/history-with-rollback.json" ,
} , {
name : "history with rollback revision yaml" ,
cmd : "history angry-bird --output yaml" ,
rels : rels ,
golden : "output/history-with-rollback.yaml" ,
} }
runTestCmd ( t , tests )
}
func TestHistoryOutputCompletion ( t * testing . T ) {
outputFlagCompletionTest ( t , "history" )
}
@ -173,6 +241,31 @@ func TestReleaseInfoMarshalJSON(t *testing.T) {
} ,
expected : ` { "revision":0,"updated":"2025-10-08T12:00:00Z","status":"failed","chart":"mychart-1.0.0","app_version":"1.0.0","description":"Install failed"} ` ,
} ,
{
name : "with rollback revision" ,
info : releaseInfo {
Revision : 3 ,
Updated : updated ,
Status : "deployed" ,
Chart : "mychart-1.0.0" ,
AppVersion : "1.0.0" ,
RollbackRevision : 1 ,
Description : "Rollback to 1" ,
} ,
expected : ` { "revision":3,"updated":"2025-10-08T12:00:00Z","status":"deployed","chart":"mychart-1.0.0","app_version":"1.0.0","rollback_revision":1,"description":"Rollback to 1"} ` ,
} ,
{
name : "without rollback revision" ,
info : releaseInfo {
Revision : 1 ,
Updated : updated ,
Status : "deployed" ,
Chart : "mychart-1.0.0" ,
AppVersion : "1.0.0" ,
Description : "Initial install" ,
} ,
expected : ` { "revision":1,"updated":"2025-10-08T12:00:00Z","status":"deployed","chart":"mychart-1.0.0","app_version":"1.0.0","description":"Initial install"} ` ,
} ,
}
for _ , tt := range tests {
@ -255,6 +348,31 @@ func TestReleaseInfoUnmarshalJSON(t *testing.T) {
Description : "Installing" ,
} ,
} ,
{
name : "with rollback revision" ,
input : ` { "revision":3,"updated":"2025-10-08T12:00:00Z","status":"deployed","chart":"mychart-1.0.0","app_version":"1.0.0","rollback_revision":1,"description":"Rollback to 1"} ` ,
expected : releaseInfo {
Revision : 3 ,
Updated : updated ,
Status : "deployed" ,
Chart : "mychart-1.0.0" ,
AppVersion : "1.0.0" ,
RollbackRevision : 1 ,
Description : "Rollback to 1" ,
} ,
} ,
{
name : "without rollback revision field" ,
input : ` { "revision":1,"updated":"2025-10-08T12:00:00Z","status":"deployed","chart":"mychart-1.0.0","app_version":"1.0.0","description":"Install"} ` ,
expected : releaseInfo {
Revision : 1 ,
Updated : updated ,
Status : "deployed" ,
Chart : "mychart-1.0.0" ,
AppVersion : "1.0.0" ,
Description : "Install" ,
} ,
} ,
}
for _ , tt := range tests {
@ -271,6 +389,7 @@ func TestReleaseInfoUnmarshalJSON(t *testing.T) {
assert . Equal ( t , tt . expected . Status , info . Status )
assert . Equal ( t , tt . expected . Chart , info . Chart )
assert . Equal ( t , tt . expected . AppVersion , info . AppVersion )
assert . Equal ( t , tt . expected . RollbackRevision , info . RollbackRevision )
assert . Equal ( t , tt . expected . Description , info . Description )
} )
}
@ -300,6 +419,7 @@ func TestReleaseInfoRoundTrip(t *testing.T) {
assert . Equal ( t , original . Status , decoded . Status )
assert . Equal ( t , original . Chart , decoded . Chart )
assert . Equal ( t , original . AppVersion , decoded . AppVersion )
assert . Equal ( t , original . RollbackRevision , decoded . RollbackRevision )
assert . Equal ( t , original . Description , decoded . Description )
}