<commit_before>require "spec"
require "http/client"
require "uuid"
require "../src/psykube"
require "../src/cli/main"

class Exited < Exception; end

class Admiral::Command
  def exit(int : Int32 = 0)
    raise Exited.new("exited")
  end
end

def kubectl(args : String)
  bin = Psykube::CLI::Commands::Kubectl.bin
  File.exists?(bin) || raise("kubectl not found")
  Process.run(bin, args.split(" "))
end

macro psykube_it(command, timeout = 30)
  command = {{command}}
  it "should run `psykube #{command}` and not fail" do
    puts ""
    Psykube::CLI.run({{ command }})
  end
end

Dir.cd("spec") do
  namespace = "psykube-test-#{UUID.random}"

  describe Psykube::CLI do
    psykube_it "init --overwrite --namespace=#{namespace} --name=psykube-test --registry-host=#{ENV["CI_REGISTRY"]} --registry-user=gitlab-ci-token --registry-password=#{ENV["CI_JOB_TOKEN"]} --port http=80"
    psykube_it "create-namespace"
    psykube_it "generate"
    psykube_it "apply"
    psykube_it "status"
    psykube_it "push"

    # it "should run exec" do
    #   Process.fork { Psykube::CLI.run "exec -- echo 'hello world'" }.wait
    # end
    #
    # it "should port forward" do
    #   process = Process.fork { Psykube::CLI.run "port-forward 9292:80" }
    #   sleep 5
    #   HTTP::Client.get("http://localhost:9292").body.lines.first.strip.should eq "hello psykube"
    #   process.kill
    #   process.wait
    # end
    #
    # it "should show logs" do
    #   process = Process.fork { Psykube::CLI.run "logs" }
    #   sleep 5
    #   process.kill
    #   process.wait
    # end

    psykube_it "copy-namespace #{namespace} #{namespace}-copy --force"

    # Cleanup
    # psykube_it "delete -y"
    # psykube_it "delete-namespace -y"

    it "deletes the namespace" do
      # kubectl "delete namespace #{namespace}-copy"
      # kubectl "delete namespace #{namespace}"
    end
  end
end<commit_msg>revert spec<commit_after>require "spec"
require "http/client"
require "uuid"
require "../src/psykube"
require "../src/cli/main"

class Exited < Exception; end

class Admiral::Command
  def exit(int : Int32 = 0)
    raise Exited.new("exited")
  end
end

def kubectl(args : String)
  bin = Psykube::CLI::Commands::Kubectl.bin
  File.exists?(bin) || raise("kubectl not found")
  Process.run(bin, args.split(" "))
end

macro psykube_it(command, timeout = 30)
  command = {{command}}
  it "should run `psykube #{command}` and not fail" do
    puts ""
    Psykube::CLI.run({{ command }})
  end
end

Dir.cd("spec") do
  ["", " --v1"].each do |v|
    namespace = "psykube-test-#{UUID.random}"

    describe Psykube::CLI do
      psykube_it "init --overwrite --namespace=#{namespace} --name=psykube-test --registry-host=gcr.io --registry-user=waldrip-net --port http=80 #{v}"
      psykube_it "create-namespace"
      psykube_it "generate"
      psykube_it "apply"
      psykube_it "status"
      psykube_it "push"

      # it "should run exec" do
      #   Process.fork { Psykube::CLI.run "exec -- echo 'hello world'" }.wait
      # end
      #
      # it "should port forward" do
      #   process = Process.fork { Psykube::CLI.run "port-forward 9292:80" }
      #   sleep 5
      #   HTTP::Client.get("http://localhost:9292").body.lines.first.strip.should eq "hello psykube"
      #   process.kill
      #   process.wait
      # end
      #
      # it "should show logs" do
      #   process = Process.fork { Psykube::CLI.run "logs" }
      #   sleep 5
      #   process.kill
      #   process.wait
      # end

      psykube_it "copy-namespace #{namespace} #{namespace}-copy --force"

      # Cleanup
      psykube_it "delete -y"
      psykube_it "delete-namespace -y"

      it "deletes the namespace" do
        kubectl "delete namespace #{namespace}-copy"
        kubectl "delete namespace #{namespace}"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.14524993457210156, 'fraction_numerical': 0.010206752159120648, 'mean_word_length': 2.784158415841584, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '61783', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1352, 'n_words': 318}