mirror of
https://github.com/outbackdingo/terraform-provider-util.git
synced 2026-01-27 10:20:41 +00:00
* It's conventional to implement Terraform providers within an internal package, since they're not intended to be consumed or relied upon as Go libraries
88 lines
1.2 KiB
Go
88 lines
1.2 KiB
Go
package nixane
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var awkballABC = `#### configuration.nix
|
|
{ modulesPath, lib, pkgs, ...}:
|
|
{
|
|
system.stateVersion = "24.05";
|
|
imports = [ "${toString modulesPath}/nixpkgs" ./modules/server.nix ];
|
|
}
|
|
#### modules/server.nix
|
|
{ lib, pkgs, ...}:
|
|
{
|
|
imports = [ ./feature.nix ];
|
|
services.openssh = {
|
|
enable = true;
|
|
};
|
|
}
|
|
#### modules/feature.nix
|
|
{ pkgs }:
|
|
let
|
|
x = 1;
|
|
{
|
|
inherit x;
|
|
options = {};
|
|
config = {};
|
|
}
|
|
`
|
|
|
|
var awkballBC = `#### configuration.nix
|
|
{ lib, pkgs, ...}:
|
|
{
|
|
imports = [ ./modules/feature.nix ];
|
|
services.openssh = {
|
|
enable = true;
|
|
};
|
|
}
|
|
#### modules/feature.nix
|
|
{ pkgs }:
|
|
let
|
|
x = 1;
|
|
{
|
|
inherit x;
|
|
options = {};
|
|
config = {};
|
|
}
|
|
`
|
|
|
|
var awkballC = `#### configuration.nix
|
|
{ pkgs }:
|
|
let
|
|
x = 1;
|
|
{
|
|
inherit x;
|
|
options = {};
|
|
config = {};
|
|
}
|
|
`
|
|
|
|
func TestEncode(t *testing.T) {
|
|
cases := []struct {
|
|
modules []*NixOSModule
|
|
expected string
|
|
}{
|
|
{
|
|
[]*NixOSModule{moduleA, moduleB, moduleC},
|
|
awkballABC,
|
|
},
|
|
{
|
|
[]*NixOSModule{moduleB, moduleC},
|
|
awkballBC,
|
|
},
|
|
{
|
|
[]*NixOSModule{moduleC},
|
|
awkballC,
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
awkball := EncodeToAwkball("configuration.nix", c.modules)
|
|
assert.Equal(t, c.expected, awkball)
|
|
}
|
|
}
|