0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-11-09 17:10:41 +00:00
wp-git-action/plugin/util_test.go

54 lines
985 B
Go
Raw Normal View History

2024-05-06 18:29:57 +00:00
package plugin
import (
"fmt"
"os"
"path/filepath"
"testing"
2024-05-06 19:04:48 +00:00
"github.com/stretchr/testify/assert"
)
func TestWriteNetrc(t *testing.T) {
tests := []struct {
name string
path string
machine string
login string
password string
wantErr bool
}{
{
name: "valid input",
path: t.TempDir(),
machine: "example.com",
login: "user",
password: "pass",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := WriteNetrc(tt.path, tt.machine, tt.login, tt.password)
if tt.wantErr {
2024-05-06 19:04:48 +00:00
assert.Error(t, err)
return
}
2024-05-06 19:04:48 +00:00
assert.NoError(t, err)
netrcPath := filepath.Join(tt.path, ".netrc")
_, err = os.Stat(netrcPath)
2024-05-06 19:04:48 +00:00
assert.NoError(t, err)
content, err := os.ReadFile(netrcPath)
2024-05-06 19:04:48 +00:00
assert.NoError(t, err)
expected := fmt.Sprintf("machine %s\nlogin %s\npassword %s\n", tt.machine, tt.login, tt.password)
2024-05-06 19:04:48 +00:00
assert.Equal(t, expected, string(content))
})
}
}