2024-04-24 22:59:22 +03:00
package main
import (
2024-04-25 12:11:55 +03:00
"context"
"path/filepath"
2024-04-24 22:59:22 +03:00
"testing"
"time"
"github.com/google/go-cmp/cmp"
2024-04-25 12:11:55 +03:00
"github.com/spf13/afero"
"github.com/stretchr/testify/require"
2024-04-24 22:59:22 +03:00
)
func Test_removeMainlineBlurb ( t * testing . T ) {
t . Parallel ()
tests := [] struct {
name string
body string
want string
}{
{
name : "NoMainlineBlurb" ,
body : `## Changelog
### Chores
- Add support for additional Azure Instance Identity RSA Certificates (#13028) (@kylecarbs)
Compare: [` + "`" + `v2.10.1...v2.10.2` + "`" + `](https://github.com/coder/coder/compare/v2.10.1...v2.10.2)
## Container image
- ` + "`" + `docker pull ghcr.io/coder/coder:v2.10.2` + "`" + `
## Install/upgrade
2024-07-10 21:31:37 +03:00
Refer to our docs to [install](https://coder.com/docs/install) or [upgrade](https://coder.com/docs/admin/upgrade) Coder, or use a release asset below.
2024-04-24 22:59:22 +03:00
` ,
want : `## Changelog
### Chores
- Add support for additional Azure Instance Identity RSA Certificates (#13028) (@kylecarbs)
Compare: [` + "`" + `v2.10.1...v2.10.2` + "`" + `](https://github.com/coder/coder/compare/v2.10.1...v2.10.2)
## Container image
- ` + "`" + `docker pull ghcr.io/coder/coder:v2.10.2` + "`" + `
## Install/upgrade
2024-07-10 21:31:37 +03:00
Refer to our docs to [install](https://coder.com/docs/install) or [upgrade](https://coder.com/docs/admin/upgrade) Coder, or use a release asset below.
2024-04-24 22:59:22 +03:00
` ,
},
{
name : "WithMainlineBlurb" ,
body : `## Changelog
> [!NOTE]
2024-07-10 21:31:37 +03:00
> This is a mainline Coder release. We advise enterprise customers without a staging environment to install our [latest stable release](https://github.com/coder/coder/releases/latest) while we refine this version. Learn more about our [Release Schedule](https://coder.com/docs/install/releases).
2024-04-24 22:59:22 +03:00
### Chores
- Add support for additional Azure Instance Identity RSA Certificates (#13028) (@kylecarbs)
Compare: [` + "`" + `v2.10.1...v2.10.2` + "`" + `](https://github.com/coder/coder/compare/v2.10.1...v2.10.2)
## Container image
- ` + "`" + `docker pull ghcr.io/coder/coder:v2.10.2` + "`" + `
## Install/upgrade
2024-07-10 21:31:37 +03:00
Refer to our docs to [install](https://coder.com/docs/install) or [upgrade](https://coder.com/docs/admin/upgrade) Coder, or use a release asset below.
2024-04-24 22:59:22 +03:00
` ,
want : `## Changelog
### Chores
- Add support for additional Azure Instance Identity RSA Certificates (#13028) (@kylecarbs)
Compare: [` + "`" + `v2.10.1...v2.10.2` + "`" + `](https://github.com/coder/coder/compare/v2.10.1...v2.10.2)
## Container image
- ` + "`" + `docker pull ghcr.io/coder/coder:v2.10.2` + "`" + `
## Install/upgrade
2024-07-10 21:31:37 +03:00
Refer to our docs to [install](https://coder.com/docs/install) or [upgrade](https://coder.com/docs/admin/upgrade) Coder, or use a release asset below.
2024-04-24 22:59:22 +03:00
` ,
},
{
name : "EntireQuotedBlurbIsRemoved" ,
body : `## Changelog
> [!NOTE]
2024-07-10 21:31:37 +03:00
> This is a mainline Coder release. We advise enterprise customers without a staging environment to install our [latest stable release](https://github.com/coder/coder/releases/latest) while we refine this version. Learn more about our [Release Schedule](https://coder.com/docs/install/releases).
2024-04-24 22:59:22 +03:00
> This is an extended note.
> This is another extended note.
### Best release yet!
Enjoy.
` ,
want : `## Changelog
### Best release yet!
Enjoy.
` ,
},
}
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
t . Parallel ()
if diff := cmp . Diff ( removeMainlineBlurb ( tt . body ), tt . want ); diff != "" {
2024-04-25 12:11:55 +03:00
require . Fail ( t , "removeMainlineBlurb() mismatch (-want +got):\n%s" , diff )
2024-04-24 22:59:22 +03:00
}
})
}
}
func Test_addStableSince ( t * testing . T ) {
t . Parallel ()
date := time . Date ( 2024 , time . April , 23 , 0 , 0 , 0 , 0 , time . UTC )
body := "## Changelog"
2024-05-17 11:25:10 +03:00
want := "> ## Stable (since April 23, 2024)\n\n## Changelog"
got := addStableSince ( date , body )
2024-04-24 22:59:22 +03:00
2024-05-17 11:25:10 +03:00
if diff := cmp . Diff ( want , got ); diff != "" {
2024-04-25 12:11:55 +03:00
require . Fail ( t , "addStableSince() mismatch (-want +got):\n%s" , diff )
}
2024-05-17 11:25:10 +03:00
// Test that it doesn't add twice.
got = addStableSince ( date , got )
if diff := cmp . Diff ( want , got ); diff != "" {
require . Fail ( t , "addStableSince() mismatch (-want +got):\n%s" , diff , "addStableSince() should not add twice" )
}
2024-04-25 12:11:55 +03:00
}
func Test_release_autoversion ( t * testing . T ) {
t . Parallel ()
ctx := context . Background ()
dir := filepath . Join ( "testdata" , "autoversion" )
fs := afero . NewCopyOnWriteFs ( afero . NewOsFs (), afero . NewMemMapFs ())
r := releaseCommand {
fs : afero . NewBasePathFs ( fs , dir ),
}
err := r . autoversion ( ctx , "mainline" , "v2.11.1" )
require . NoError ( t , err )
err = r . autoversion ( ctx , "stable" , "v2.9.4" )
require . NoError ( t , err )
files , err := filepath . Glob ( filepath . Join ( dir , "docs" , "*.md" ))
require . NoError ( t , err )
for _ , file := range files {
t . Run ( file , func ( t * testing . T ) {
t . Parallel ()
got , err := afero . ReadFile ( fs , file )
require . NoError ( t , err )
want , err := afero . ReadFile ( fs , file + ".golden" )
require . NoError ( t , err )
if diff := cmp . Diff ( string ( got ), string ( want )); diff != "" {
require . Failf ( t , "mismatch (-want +got):\n%s" , diff )
}
})
2024-04-24 22:59:22 +03:00
}
}