diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000..26d33521af --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000000..105ce2da2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/learn-cicd-starter.iml b/.idea/learn-cicd-starter.iml new file mode 100644 index 0000000000..d0876a78d0 --- /dev/null +++ b/.idea/learn-cicd-starter.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000..9fe11f1e05 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..d0adac68cd --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..d3c4519bb8 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index c2bec0368b..48ef5ad7f0 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,12 @@ go build -o notely && ./notely *This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`. You do *not* need to set up a database or any interactivity on the webpage yet. Instructions for that will come later in the course! + +Felbote's version of Boot.dev's Notely app. + +#Create a new branch called addtests. I like to name my branches after the change I'm about to make, and in this case, we're about to add tests. +git switch -c addtests + +When you create a new branch, it only exists locally. Push this new branch up to GitHub: +git push origin addtests. + diff --git a/go fmt b/go fmt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/internal/auth/auth_test.g b/internal/auth/auth_test.g new file mode 100644 index 0000000000..9afecde33b --- /dev/null +++ b/internal/auth/auth_test.g @@ -0,0 +1,18 @@ +func TestGetAPIKey_FromFile(t *testing.T) { + // criar ficheiro temporário com a chave + f, err := os.CreateTemp("", "apikey-") + if err != nil { t.Fatalf("CreateTemp: %v", err) } + defer os.Remove(f.Name()) + if _, err := f.WriteString("minha-chavedearquivo"); err != nil { t.Fatalf("write: %v", err) } + f.Close() + + prev := os.Getenv("NOTELY_API_KEY_FILE") + defer os.Setenv("NOTELY_API_KEY_FILE", prev) + os.Setenv("NOTELY_API_KEY_FILE", f.Name()) + + got, err := auth.GetAPIKey() + if err != nil { t.Fatalf("esperava nil, obteve: %v", err) } + if got != "minha-chavedearquivo" { + t.Fatalf("esperava 'minha-chavedearquivo', obteve: %q", got) + } +} \ No newline at end of file diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go new file mode 100644 index 0000000000..811e282781 --- /dev/null +++ b/internal/auth/auth_test.go @@ -0,0 +1,28 @@ +package auth + +import ( + "os" + "testing" +) + +func TestGetAPIKey_FromEnv(t *testing.T) { + // t.Setenv está disponível em Go 1.17+ e restaura automaticamente ao fim do teste + t.Setenv("NOTELY_API_KEY", "env-key-123") + + got := GetAPIKey() + want := "env-key-123" + + if got != want { + t.Fatalf("GetAPIKey() = %q; want %q", got, want) + } +} + +func TestGetAPIKey_EmptyWhenUnset(t *testing.T) { + // Assegura que a env está limpa + os.Unsetenv("NOTELY_API_KEY") + + got := GetAPIKey() + if got != "" { + t.Fatalf("expected empty string when env unset, got %q", got) + } +} diff --git a/tests/test_sample.py b/tests/test_sample.py new file mode 100644 index 0000000000..b9f408e5a2 --- /dev/null +++ b/tests/test_sample.py @@ -0,0 +1,2 @@ +def test_truth(): + assert True git add